import pyglet

import singleton
from cairointegration import CairoImage
import interface

class Main(singleton.Singleton):
    def __init__(self):
        singleton.Singleton.__init__(self)
    
    def init(self):
        self.w = w = 1024
        self.h = h = 600
        self.window = pyglet.window.Window(width=w, height=h)
        
        self.cairoImage = CairoImage(w, h)
        self.ctx = self.cairoImage.ctx
        self.ctx.scale(min(w, h), min(w, h))
        
        self.cursor = interface.Cursor()
        
        @self.window.event
        def on_draw():
            self.cairoImage.draw()

main = singleton.Handle(Main)

if __name__ == '__main__':
    if __debug__:
        import cProfile
        cProfile.run('main.init()')
    else:
        main.init()
    pyglet.app.run()